import { getDB } from "../../utils/db/mysql";
export default defineEventHandler(async (req) => {
  let con = getDB();
  let body = await readBody(req);
  //   如果有中文则转化为中文编码
  
  const url = body.url12;  
  console.log(url,'新闻标题');
  
   // 将counter cookie增加1
  setCookie(req, 'newsitem', url)
  
// 读取counter cookie
let cooknewsitem = getCookie(req, 'newsitem') || 0
  let [result] = await con.execute(
    `SELECT * FROM pigeonhole_item WHERE routekey LIKE '%${cooknewsitem}%';`
  );
  //释放连接
  await con.end();
  if (result.length != 0) {
    return {
      code: 2000,
      data: result,
    };
  } else {
    return {
      code: 4003,
      data: "没有数据",
    };
  }

  ///////////////////////////////
});
